{temp('kefu/head')}
</head>
<body>
<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i>首页
	<span class="c-gray en">&gt;</span>新闻管理
	<span class="c-gray en">&gt;</span>新闻列表
	<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>
<div class="pd-20">
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="dels()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i>批量删除
			</a>
			<a class="btn btn-primary radius" onclick="article_add('添加新闻','{$_url}/kefu/?act=news&met=add_news')" href="javascript:;">
				<i class="Hui-iconfont">&#xe600;</i>添加新闻
			</a>
		</span>
		<span class="r">共有数据：<strong>{$xwnum}</strong> 条</span>
	</div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">ID</th>
					<th>标题</th>
					<th width="120">发布时间</th>
					<th width="120">是否推荐</th>
					<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
			{if(@$xw)}
				{foreach($xw as $k=>$v)}
				<tr class="text-c">
					<td><input type="checkbox" value="{$v['id']}" name="checkbox"></td>
					<td>{$v['id']}</td>
					<td class="text-l">
						<span class="text-primary">
						{$v['title']}
						</span>
					</td>
					<td>{code(echo date('Y-m-d H:i',$v['time']))}</td>
					<td><span onclick="tj({$v['id']})" style="cursor:pointer;">{if($v['tj'] == 1)}推荐{else}未推荐{/if}</span></td>
					<td class="f-14 td-manage">
						<a style="text-decoration:none" class="ml-5" onClick="article_edit('编辑新闻','{$_url}/kefu/?act=news&met=xiu_news&id={$v['id']}',{$v['id']})" href="javascript:;" title="编辑">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a style="text-decoration:none" class="ml-5" onClick="article_del({$v['id']})" href="javascript:;" title="删除">
							<i class="Hui-iconfont">&#xe6e2;</i>
						</a>
					</td>
				</tr>
				{/foreach}
			{/if}
			</tbody>
		</table>
	</div>
</div>
<script type="text/javascript">
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
});

/*新闻-推荐*/
function tj(id){
	$.post('{$_url}/kefu/?act=news&met=news_tj',{id:id},function(data){
		if(data == 'cg'){
			layer.alert('修改成功');
			setTimeout(function(){location.href = '{$_url}/kefu/?act=news';},800);return ;
		}else if(data == 'error'){
			layer.alert('修改失败');return ;
		}else if(data == '-1'){
			layer.alert('修改失败');return ;
		}
	});
}

/*新闻-添加*/
function article_add(title,url,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*新闻-编辑*/
function article_edit(title,url,id,w,h){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*新闻-删除*/
function article_del(id){
	layer.confirm('确认要删除吗？',function(index){
		$.post('{$_url}/kefu/?act=news&met=news_d',{id:id},function(data){
			if(data == 'cg'){
				layer.alert('删除成功');
				setTimeout(function(){location.href = '{$_url}/kefu/?act=news';},800);return ;
			}else if(data == 'error'){
				layer.alert('删除失败');return ;
			}
		});
	});
}

/*新闻-全部删除*/
function dels(){
	layer.confirm('确认要删除吗？',function(index){
		var xq = 'checkbox';
		var xi = '';
		var i = $('input:checkbox[name="'+xq+'"]:checked');
			i.each(function(){
			var a = this.value;
			xi += a + ',';
		});
		$.post('{$_url}/kefu/?act=news&met=news_ds',{xi:xi},function(data){
			if(data == 'cg'){
				layer.alert('删除成功');
				setTimeout(function(){location.href = '{$_url}/kefu/?act=news';},800);return ;
			}else if(data == 'error'){
				layer.alert('删除失败');return ;
			}else if(data == '-1'){
				layer.alert('请选择新闻后再进行操作');return ;
			}
		});
	});
}
</script>
{temp('kefu/foot')}
</body>
</html>